Skip to content

fix(embed-core): tract backend loads nomic-embed-text-v1.5 (symbolic input dims, inputs bound by name) - #1502

Open
aepod wants to merge 1 commit into
ruvnet:mainfrom
weave-logic-ai:fix/embed-core-tract-nomic
Open

aepod wants to merge 1 commit into
ruvnet:mainfrom
weave-logic-ai:fix/embed-core-tract-nomic

Conversation

@aepod

@aepod aepod commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

TractEmbedder could not run nomic-embed-text-v1.5, and any graph whose declared input order differs from input_ids, attention_mask, token_type_ids was fed the wrong tensors. Two causes, both in tract_backend.rs.

Inputs were pinned to a concrete [1, seq_len]. HF exports declare batch_size and sequence_length symbolically, and nomic's value_info at the first Gather uses them, so optimize failed with "Impossible to unify Sym(batch_size) with Val(1)". The inputs now use the graph's own symbols.

Inputs were bound by position as [ids, mask, types]. nomic declares input_ids, token_type_ids, attention_mask, so the mask went into token_type_ids (min cosine vs ort 0.42 with only the first fix). Inputs are now bound by name; unnamed graphs keep the old positional order. OrtEmbedder already binds by name (ort_backend.rs).

The tract floor for the wasm feature rises to 0.23.10 and Cargo.lock is updated. With the locked 0.23.8, nomic still fails at optimize on the rotary Range op ("Translating node /encoder/layers.0/attn/rotary_emb/Range"); with 0.23.10 it loads. 0.23.9 was not tried. The lock bump also moves minijinja 2.24 -> 3.1.0, adds metrics and rapidhash and drops memo-map (all tract 0.23.10 dependencies). Happy to split the lock bump into its own PR if you prefer.

Not changed: the plan cache is still keyed per padded length, although the plans are now symbolic and so identical (could collapse to one plan in a follow-up). examples/onnx-embeddings-wasm/src/model.rs has the same positional binding and a concrete batch dim; left alone. The symbol names batch_size and sequence_length are hardcoded, which matches the HF/Xenova exports tested here; a graph that names its dims differently would need the declared dims used instead.

Tests: new tests/tract_named_inputs.rs, #[ignore]d and real models only (hashes pinned and checked; missing models skip). nomic tract vs stored onnxruntime vectors: min cosine 0.9999993 (3 texts; before the change it fails to load). bge-small and all-MiniLM-L6-v2: cosine 0.99999934 or better against vectors recorded from the unpatched backend, single and batched, 5 texts of different lengths. Input binding: bge and MiniLM weights with graph.input rewritten to other orders (including nomic's) match the stock order at cosine >= 0.9999992; before the change one case returns cosine 0.54 and the reversed MiniLM case panics in tract's Gather. Existing crate tests 15/15 on both sides. Run with --features wasm -- --include-ignored; set RUVECTOR_EMBED_MODELS_DIR if the models are not under npm/packages/typesafe/models (nomic goes in nomic-embed-text-v1.5/{model.onnx,tokenizer.json}). Not run: the native/ort parity.rs and a wasm32 build.

…input dims, inputs bound by name)

TractEmbedder could not run nomic-embed-text-v1.5, and any graph whose
declared input order differs from input_ids, attention_mask,
token_type_ids was fed the wrong tensors. Two causes, both in
tract_backend.rs:

- Inputs were pinned to a concrete [1, seq_len]. HF exports declare
  batch_size and sequence_length symbolically, and nomic's value_info at
  the first Gather uses them, so optimize failed with "Impossible to
  unify Sym(batch_size) with Val(1)". The inputs now use the graph's own
  symbols.
- Inputs were bound by position as [ids, mask, types]. nomic declares
  input_ids, token_type_ids, attention_mask, so the mask went into
  token_type_ids. Inputs are now bound by name; unnamed graphs keep the
  old positional order. OrtEmbedder already binds by name.

The tract floor for the wasm feature rises to 0.23.10 and Cargo.lock is
updated: with the locked 0.23.8, nomic still fails at optimize on the
rotary Range op. The lock bump also moves minijinja 2.24 -> 3.1.0, adds
metrics and rapidhash and drops memo-map (tract 0.23.10 dependencies).

Tests: new tests/tract_named_inputs.rs, #[ignore]d, real models only
(hashes pinned; missing models skip). nomic vs stored onnxruntime
vectors: min cosine 0.9999993 (failed to load before). bge-small and
all-MiniLM-L6-v2 match vectors recorded from the unpatched backend at
cosine >= 0.99999934, single and batched. Graphs with reordered inputs
match the stock order at cosine >= 0.9999992 (before: 0.54, and a panic
in tract's Gather). Existing crate tests 15/15.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant